package com.cty;


import com.cty.pojo.User;
import com.cty.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class UserServiceImpl {

    @Autowired
    private UserService userService;

    @Test
    public void save() {
        List<User> userList = new ArrayList<>();
        User user = new User();
        user.setAge(18);
        user.setName("ergouzi");
        user.setEmail("jj");
        userList.add(user);

        User user1= new User();
        user1.setAge(18);
        user1.setName("lvdandan");
        user1.setEmail("jj");
        userList.add(user1);


        boolean result = userService.saveBatch(userList);//保存一个集合中的元素
        System.out.println("result = " + result);

    }

    @Test
    public void saveOrUpdate() {
        //保存或者更新方法
        //id已存在就更新，id不存在或者没有id就保存
        User user = new User();
        user.setId(1L);
        user.setName("小明");
        user.setAge(20);
        user.setEmail("xxxx");
        boolean b = userService.saveOrUpdate(user);
        System.out.println("b = " + b);
    }

    @Test
    public void remove() {
        //根据id删除
        boolean b = userService.removeById(1946132109737504769L);
        System.out.println("b = " + b);
    }

    @Test
    public void getByid() {
        User user = userService.getById(1);
        System.out.println("user = " + user);
    }

    @Test
    public void updateById() {
        User user = new User();
        user.setId(1L);
        user.setEmail("xxxxxxx");
        user.setAge(23);
        user.setName("xiaohong");
        boolean  b = userService.updateById(user);
        System.out.println("b = " + b);
    }

}
